<?php
namespace app\admin\controller;


use app\admin\logic\BrandLogic;
use app\BaseController;
use think\facade\View;
use think\facade\Request;
use app\admin\logic\GoodsLogic;

class Brand extends BaseController
{
    //品牌列表
    public function brandList()
    {
        //接值
        $param = Request::param();
        //拼接where语句
        list($where,$whereOr) = GoodsLogic::brandWhere($param);
        //留值
        $data = GoodsLogic::brandData($param);
        View::assign($data);
        //查询语句
//        $list = Brand::brand($where,$whereOr);
        $list = \app\admin\model\Brand::brand($where,$whereOr);
        View::assign('list',$list);
        return View::fetch();
    }
    //品牌添加
    public function brandAdd()
    {
        if (Request::isPost()){
            //接值
            $post = Request::post();
            //逻辑层处理添加数据
            $add = BrandLogic::addBrandInfo($post);
            //模型层处理添加数据
            $res = \app\admin\model\Brand::addBrandAttr($add);
            if ($res){
                $this->success('添加成功',url('brandList'));
            }else{
                $this->error('添加失败');
            }
        }
        return View::fetch();
    }
    //品牌单个删除
    public function brandDel()
    {
        //接参
        $get = Request::get();
        //模型层软删除数据
        $res = \app\admin\model\Brand::delBrandAttr($get);
        //判断删除语句是否执行
        if ($res){
            $this->success('删除成功',url('brandList'));
        }else{
            $this->error('删除失败');
        }
    }
    //品牌多个删除
    public function brandDels()
    {
        //接参
        $get = Request::get();
        //模型层软删除数据
        $res = \app\admin\model\Brand::delsBrandAttr($get);
        //判断删除语句是否执行
        if ($res){
            $this->success('删除成功',url('brandList'));
        }else{
            $this->error('删除失败');
        }
    }
}